package cn.codingjc.nacos;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;

import java.util.Properties;

/**
 * @author: Allen.qiu
 * @Date: 2022/7/16 17:04
 * @description:
 **/
public class PublishNacosConfig {
    public static final String NACOS_SERVER = "192.168.239.131:8848";
    public static final String DATA_ID = "cn.codingjc.nacos.microcloud.config";
    public static final String GROUP = "MICROCLOUD_GROUP";
    public static final String NAMESPACE = "a3575eaf-f53a-481a-807a-9277fe43e87f";

    public static void main(String[] args) throws NacosException {
        String content = "jacky";
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.SERVER_ADDR, NACOS_SERVER);
        properties.put(PropertyKeyConst.NAMESPACE, NAMESPACE);
        ConfigService configService = NacosFactory.createConfigService(properties);
        boolean result = configService.publishConfig(DATA_ID, GROUP, content);
        System.out.println("publicsh result:" + result);
    }
}
